//package com.wonghiu.framework.cluster.directory.imp;
//
//import com.wonghiu.framework.cluster.directory.ConsumerDirectory;
//import io.netty.channel.Channel;
//import lombok.extern.slf4j.Slf4j;
//
//import java.net.InetSocketAddress;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @Author wonghiu
// * @Date 2021/8/11 16:23
// * @Version 1.0.1
// */
//@Slf4j
//public class ConsumerDirectoryImp implements ConsumerDirectory {
//
//    private final Map<String, Channel> channelMap;
//
//    public ConsumerDirectoryImp() {
//        channelMap = new ConcurrentHashMap<>();
//    }
//    @Override
//    public Channel[] get(InetSocketAddress inetSocketAddress) {
//        String key = inetSocketAddress.toString();
//        // determine if there is a connection for the corresponding address
//        if (channelMap.containsKey(key)) {
//            Channel channel = channelMap.get(key);
//            // if so, determine if the connection is available, and if so, get it directly
//            if (channel != null && channel.isActive()) {
//                return channel;
//            } else {
//                channelMap.remove(key);
//            }
//        }
//        return null;
//    }
//    @Override
//    public void set(InetSocketAddress inetSocketAddress, Channel channel) {
//        String key = inetSocketAddress.toString();
//        channelMap.put(key, channel);
//    }
//    @Override
//    public void remove(InetSocketAddress inetSocketAddress) {
//        String key = inetSocketAddress.toString();
//        channelMap.remove(key);
//        log.info("Channel map size :[{}]", channelMap.size());
//    }
//}
//
